package com.uum.admin.controller;


import cn.hutool.core.util.StrUtil;
import cn.hutool.extra.servlet.ServletUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.uum.admin.pojo.entity.SysLoginLog;
import com.uum.admin.pojo.query.LoginLogPageQuery;
import com.uum.admin.pojo.vo.LoginLogPageVO;
import com.uum.admin.service.SysLoginLogService;
import com.uum.common.core.annotation.Operation;
import com.uum.common.core.enums.BusinessType;
import com.uum.common.core.result.Result;
import com.uum.web.util.IpUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.Date;
import java.util.Map;

@Api(tags = "登陆日志接口")
@RestController
@RequestMapping("/api/v1/login-log")
public class SysLoginLogController {

    @Resource
    private SysLoginLogService sysLoginLogService;

    @Operation(description = "查询登录日志列表",businessType = BusinessType.QUERY,isSaveRequestData = false)
    @ApiOperation(value = "登录日志列表")
    @GetMapping("page")
    public Result LoginLogPage(LoginLogPageQuery logPageQuery){
        Page<LoginLogPageVO> result = sysLoginLogService.page(logPageQuery);
        return Result.success(result);
    }


    @Operation(description = "删除用户日志",businessType = BusinessType.DELETE)
    @ApiOperation(value = "批量删除用户日志")
    @DeleteMapping("delete/{ids}")
    public Result deleteLoginLog(@PathVariable String ids) {
        boolean result = sysLoginLogService.removeByIds(Arrays.asList(ids.split(",")));
        return Result.judge(result);
    }
}

